package com.mdd.front.controller.yangyangLeadingEnterprise;

import com.aliyun.dypnsapi20170525.models.GetMobileResponseBody;
import com.mdd.common.aop.NotLogin;
import com.mdd.common.aop.NotPower;
import com.mdd.common.entity.yangyangLeadingEnterprise.TAppUser;
import com.mdd.common.entity.yangyangLeadingEnterprise.common.JsonReturn;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.LoginParam;
import com.mdd.common.util.aliyunOperatorLogin.GetMobile;
import com.mdd.front.service.yangyangLeadingEnterprise.ITAppDicService;
import com.mdd.front.service.yangyangLeadingEnterprise.ITAppUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.math3.util.Pair;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/app/appUserLogin")
@Api(tags = "app用户登录注册")
public class AppUserLoginController {

    @Resource
    ITAppUserService iTAppUserService;

    @NotLogin
    @ApiIgnore
    @PostMapping(value = "/appUserRegister",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="APP用户注册")
    @ResponseBody
    public String appUserRegister(@RequestBody LoginParam param, HttpServletRequest request) {
//    public String appUserRegister(@RequestBody Map<String,Object> param, HttpServletRequest request) {
        return iTAppUserService.appUserRegister(param);
    }



//    @NotLogin
    @ApiIgnore
    @PostMapping(value = "/updateAppUserPassword",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="修改密码")
    @ResponseBody
    public String updateAppUserPassword(@RequestBody LoginParam param) {
        String result=iTAppUserService.updateAppUserPassword(param);
        return result;
    }

//    @NotLogin
    @ApiIgnore
    @PostMapping(value = "/updateAppUserPhone",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="用户修改成新的手机号")
    @ResponseBody
    public String updateAppUserPhone(@RequestBody LoginParam param) {
        String result=iTAppUserService.updateAppUserPhone(param);
        return result;
    }



//=================================================================华丽的分割线====================================================================================

    /**
     * 用户登录
     * @param param
     * @return
     */
    @NotLogin
    @PostMapping(value = "/appUserLogin",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="APP登录")
    @ResponseBody
    public String appUserLogin(@RequestBody LoginParam param,HttpServletRequest request) {
        String appVersion = request.getHeader("appVersion");
        String sysVersion = request.getHeader("sysVersion");
        String terminal = request.getHeader("terminal");
        param.setAppVersion(appVersion);
        param.setSysVersion(sysVersion);
        if(terminal!=null && !terminal.isEmpty()){
            param.setTerminal(Integer.parseInt(terminal));
        }
        String result=iTAppUserService.appUserLogin(param);
        return result;
    }

    /**
     * 用户注册协议
     * @param param
     * @return
     */
    @NotLogin
    @PostMapping(value = "/updateUserRegistrationAgreementFlag",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="用户注册协议")
    @ResponseBody
    public String updateUserRegistrationAgreementFlag(@RequestBody LoginParam param) {
        Integer registrationAgreementFlag = param.getRegistrationAgreementFlag();
        Long userId = param.getUserId();
        if(registrationAgreementFlag==null || userId==null){
            return JsonReturn.fail("必传参数不能为空",201).toJsonStr();
        }
        TAppUser appUser = new TAppUser();
        appUser.setRegistrationAgreementFlag(registrationAgreementFlag);
        appUser.setId(userId);
        iTAppUserService.updateById(appUser);
        return JsonReturn.success().toJsonStr();
    }


    /**
     * 第三方登录绑定手机号
     * @param param
     * @return
     */
    @PostMapping(value = "/bindPhone",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="第三方登录绑定手机号")
    @ResponseBody
    public String bindPhone(@RequestBody LoginParam param) {
        return iTAppUserService.bindPhone(param);
    }

    /**
     * 第三方登录设置密码
     * @param param
     * @return
     */
    @PostMapping(value = "/bindPassword",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="第三方登录设置密码")
    @ResponseBody
    public String bindPassword(@RequestBody LoginParam param) {
        return iTAppUserService.bindPassword(param);
    }

    @NotLogin
    @PostMapping(value = "/forgotPasswordStepOne",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="忘记密码第一步---验证手机号")
    @ResponseBody
    public String forgotPasswordStepOne(@RequestBody LoginParam param) {
        String result=iTAppUserService.forgotPasswordStepOne(param);
        return result;
    }

    @NotLogin
    @PostMapping(value = "/forgotPasswordStepTwo",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="忘记密码第二步---两次输入密码")
    @ResponseBody
    public String forgotPasswordStepTwo(@RequestBody LoginParam param) {
        String result=iTAppUserService.forgotPasswordStepTwo(param);
        return result;
    }

    @NotLogin
    @PostMapping(value = "/loginOut",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="退出登录")
    @ResponseBody
    public String loginOut(@RequestBody LoginParam param) {
        return iTAppUserService.loginOut(param);
    }

    @NotLogin
    @PostMapping(value = "/cancelAccount",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="注销账户")
    @ResponseBody
    public String cancelAccount(@RequestBody LoginParam param) {
        return iTAppUserService.cancelAccount(param);
    }














//    @GetMapping("/list")
//    @ApiOperation(value="【请填写功能名称】列表")
//    public AjaxResult<PageResult<TAppUserListedVo>> list(@Validated PageValidate pageValidate,
//                                                         @Validated TAppUserSearchValidate searchValidate) {
//        PageResult<TAppUserListedVo> list = iTAppUserService.list(pageValidate, searchValidate);
//        return AjaxResult.success(list);
//    }
//
//    @GetMapping("/detail")
//    @ApiOperation(value="【请填写功能名称】详情")
//    public AjaxResult<TAppUserDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
//        TAppUserDetailVo detail = iTAppUserService.detail(id);
//        return AjaxResult.success(detail);
//    }
//
////    @Log(title = "【请填写功能名称】新增")
//    @PostMapping("/add")
//    @ApiOperation(value="【请填写功能名称】新增")
//    public AjaxResult<Object> add(@Validated @RequestBody TAppUserCreateValidate createValidate) {
//        iTAppUserService.add(createValidate);
//        return AjaxResult.success();
//    }
//
//    @Log(title = "【请填写功能名称】编辑")
//    @PostMapping("/edit")
//    @ApiOperation(value="【请填写功能名称】编辑")
//    public AjaxResult<Object> edit(@Validated @RequestBody TAppUserUpdateValidate updateValidate) {
//        iTAppUserService.edit(updateValidate);
//        return AjaxResult.success();
//    }
//
//    @Log(title = "【请填写功能名称】删除")
//    @PostMapping("/del")
//    @ApiOperation(value="【请填写功能名称】删除")
//    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
//        iTAppUserService.del(idValidate.getId());
//        return AjaxResult.success();
//    }

}
